﻿var req;
var tagid;
var previous_value = "";
var current_value = "";
function goTest(obj) {
    current_value = obj.value;
    tagid = "status";
    if (current_value != "" && current_value != previous_value) {
        var url = "checkuser.asp";
        var pars = "username=" + current_value;
        retrieveURL(url, pars);
    }
}
function retrieveURL(url, pars) {
    if (window.XMLHttpRequest) { // Non-IE browsers 
        req = new XMLHttpRequest();
        req.onreadystatechange = processStateChange;
        try {
            req.open("POST", url);
            req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            req.setRequestHeader("charset", "utf-8");
            req.send(pars);
        } catch (e) {
            alert(e);
        }
        //req.send(null); 
    } else if (window.ActiveXObject) { // IE 
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = processStateChange;
            req.open("POST", url);
            req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            req.setRequestHeader("charset", "utf-8");
            req.send(pars);
        }
    }
}
function processStateChange() {
    var id = document.getElementById(tagid);
    if (req.readyState == 4) { // Complete 
        if (req.status == 200) { // OK response 
            if (req.responseText == "1") {
                id.innerHTML = "Allow.";
                id.style.color = "blue";
            } else {
                id.innerHTML = "Not allow.";
                id.style.color = "red";
            }
            previous_value = current_value;
        }
    }
}  